import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import junit.framework.TestCase;

public class LexiconArrayListTest extends TestCase
{
	/**
	 * Your test dictionary, containing words in smalltestwords.txt
	 */
	private Scanner words;

	/**
	 * Open smalltestwords.txt and give to the words instance variable. This is automatically run before each test.
	 */
	public void setUp()
	{
		try
		{
			words = new Scanner(new File("smalltestwords.txt"));
		}
		catch (FileNotFoundException e)
		{
			System.out.println(e);
			assertTrue(false);
		}
	}

	/**
	 * Closes smalltestwords.txt after each test.
	 */
	public void tearDown()
	{
		words.close();
	}

	/**
	 * A basic test for the lexicon. You should not assume that passing this test means that your code works.
	 */
	public void testLexicon()
	{
		LexiconArrayList l = new LexiconArrayList();
		l.load(words);
		
		assertFalse(l.contains(""));
		assertTrue(l.contains("a"));
		assertTrue(l.contains("gorilla"));
		assertTrue(l.contains("gore"));
		assertFalse(l.contains("armin"));
		assertFalse(l.contains("orilla"));
	}

	/**
	 * Further tests for LexiconArrayList
	 */
	public void testLexiconFurther()
	{
		LexiconTrie lex = new LexiconTrie();
		Scanner s;
		
		s = new Scanner("wa wb wc"); //separate words with spaces
		lex.load(s);
		assertEquals(lex.toString(), "w[ABC]");
		assertTrue(lex.containsPrefix("w"));
		assertTrue(lex.contains("wa"));
		assertTrue(lex.contains("wb"));
		assertTrue(lex.contains("wc"));
		assertTrue(lex.containsPrefix("wc"));

		s = new Scanner("wawbwc");
		lex.load(s);
		assertEquals(lex.toString(), "w[a[w[b[w[C]]]]]");
		assertTrue(lex.contains("wawbwc"));	
		assertTrue(lex.containsPrefix("wawbwc"));	
		assertTrue(lex.containsPrefix("wa"));
		assertFalse(lex.contains("wa"));
		assertFalse(lex.contains("wb"));
		assertFalse(lex.containsPrefix("wb"));
		
		s = new Scanner("two two three three three");
		lex.load(s);
		assertTrue(lex.contains("two"));
		assertTrue(lex.contains("three"));
		assertTrue(lex.containsPrefix("t"));
		assertTrue(lex.containsPrefix("th"));
		assertTrue(lex.containsPrefix("thr"));
		assertTrue(lex.containsPrefix("thre"));
		assertTrue(lex.containsPrefix("three"));
		assertFalse(lex.containsPrefix("threex"));
	}
}